package com.example.demo.controller.AuthorControl;

import com.example.demo.entity.BackResponseEntity;
import com.example.demo.entity.requestJson.DeleteReq;
import com.example.demo.entity.requestJson.FavoriteBookReq;
import com.example.demo.entity.requestJson.QueryFavBookReq;
import com.example.demo.entity.responseJson.BookshelfBInformationRes;
import com.example.demo.entity.responseJson.ListResult;
import com.example.demo.service.serviceImpl.ABookFavoritesServiceImpl;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiResponse;
import io.swagger.annotations.ApiResponses;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author : 洪俊新
 * @date : 2021/3/10 15:48
 * @description:
 */
@RestController
@RequestMapping("/author/favoritebook")
@Api(value = "作品收藏接口", tags = "作品收藏接口")
public class AFavoriteBookController {
    @Autowired
    private ABookFavoritesServiceImpl aBookFavoritesService;

    @ApiOperation(value = "用户收藏作品接口", notes = "")
    @ApiOperationSupport(author = "杨")
    @ApiResponses(
            @ApiResponse(code = 200, message = "处理成功")
    )

    @PostMapping("/insertfavoritebook")
    public BackResponseEntity<Object> insertFavoriteBook(@RequestBody FavoriteBookReq favoriteBookReq) {
        return aBookFavoritesService.insertFavoriteBook(favoriteBookReq);
    }

    @ApiOperation(value = "查看用户收藏作品列表接口", notes = "用于查看书架作品和个人主页收藏作品")
    @ApiOperationSupport(author = "杨")
    @ApiResponses(
            @ApiResponse(code = 200, message = "处理成功")
    )

    @GetMapping("/queryfavoritebook")
    public BackResponseEntity<ListResult<List<BookshelfBInformationRes>>> queryFavoriteBook(DeleteReq deleteReq) {
        return aBookFavoritesService.querybookshelefBook(deleteReq);
    }

    @ApiOperation(value = "查看是否收藏作品接口", notes = "user_id是此时登录的作者id")
    @ApiOperationSupport(author = "杨")
    @ApiResponses(
            @ApiResponse(code = 200, message = "处理成功")
    )

    @GetMapping("/isfavoritebook")
    public BackResponseEntity<Object> isFavoriteBook(FavoriteBookReq favoriteBookReq) {
        return aBookFavoritesService.isfavoriteBook(favoriteBookReq);
    }

    @ApiOperation(value = "取消收藏作品接口", notes = "user_id是此时登录的作者id")
    @ApiOperationSupport(author = "杨")
    @ApiResponses(
            @ApiResponse(code = 200, message = "处理成功")
    )

    @GetMapping("/unfavoritebook")
    public BackResponseEntity<Object> unFavoriteBook(FavoriteBookReq favoriteBookReq) {
        return aBookFavoritesService.unSubscribeBook(favoriteBookReq);
    }

    @ApiOperation(value = "模糊查询收藏作品接口", notes = "user_id是此时登录的作者id，用于书架查询")
    @ApiOperationSupport(author = "杨")
    @ApiResponses(
            @ApiResponse(code = 200, message = "处理成功")
    )

    @GetMapping("/fuzzyqueryfavbook")
    public BackResponseEntity<List<BookshelfBInformationRes>> fuzzyQueryFavBook(QueryFavBookReq queryFavBookReq) {
        return aBookFavoritesService.fuzzyQueryBook(queryFavBookReq);
    }
}
